package com.berwin.adapter;

import android.content.Context;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;


import com.berwin.fragments.FilesFragment;
import com.berwin.fragments.TextsFragment;

import java.util.ArrayList;
import java.util.List;

public class ViewPagerAdapter extends FragmentPagerAdapter {

    private List<String> titles;
    private List<Fragment> fragments;

    public ViewPagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        this.titles = new ArrayList<>();
        this.titles.add("文本");
        this.titles.add("文件");
        this.fragments = new ArrayList<>();
        this.fragments.add(new TextsFragment(context));
        this.fragments.add(new FilesFragment(context));
    }

    public TextsFragment getTextsFragment() {
        return (TextsFragment) this.fragments.get(0);
    }

    public FilesFragment getFilesFragment() {
        return (FilesFragment) this.fragments.get(1);
    }

    @Override
    public Fragment getItem(int position) {
        return this.fragments.get(position);
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return this.titles.get(position);
    }
}
